package cn.hd.userService.controller.role;

import cn.hd.commonService.vo.Result;
import cn.hd.commonService.annotations.LogAnnotation;
import cn.hd.commonService.enums.MethodType;
import cn.hd.userService.service.role.ISysUserRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/userRole")
@Api(tags = "用户和角色相关操作")
public class UserRoleController {

    @Autowired
    private ISysUserRoleService userRoleService;

    @PostMapping("/saveRelation")
    @ApiOperation(value = "角色分配")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleIds",value = "角色id"),
            @ApiImplicitParam(name = "userIds",value = "用户id")
    })
    @LogAnnotation(methodName = "角色分配",methodDesc = "保存角色和用户的关联关系",methodType = MethodType.POST_TYPE)
    public Result saveRelation(String roleIds,String userIds){
        Assert.hasText(roleIds,"角色id不能为空");
        Assert.hasText(userIds,"用户id不能为空");
        userRoleService.saveRelation(roleIds,userIds);
        return Result.success("分配成功");
    }
}
